package com.eqdd.yiqidian.widget;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ViewSwitcher;

import com.coorchice.library.SuperTextView;
import com.eqdd.yiqidian.ItemDakaSwitchTextCustom;
import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.base.BaseApplication;
import com.eqdd.yiqidian.utils.juster.MoveEffectAdjuster;

/**
 * Created by lvzhihao on 17-6-21.
 */

public class DakaSwitchView extends ViewSwitcher implements ViewSwitcher.ViewFactory {
    private Context context;

    public DakaSwitchView(Context context) {
        super(context);
        this.context = context;
        init();
    }

    public DakaSwitchView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    private void init() {
        this.setFactory(this);
        this.setInAnimation(AnimationUtils.loadAnimation(context, R.anim.daka_switch_in_animation));
        this.setOutAnimation(AnimationUtils.loadAnimation(context, R.anim.daka_switch_out_animation));
    }

    @Override
    public View makeView() {
        ItemDakaSwitchTextCustom inflate = DataBindingUtil.inflate(LayoutInflater.from(BaseApplication.getApplication()),
                R.layout.item_daka_switch_text, null, false);
        inflate.stvDaka.setAdjuster(new MoveEffectAdjuster())
                .setAutoAdjust(true)
                .startAnim();
        return inflate.getRoot();
    }

    public void setText(CharSequence text) {

        SuperTextView superTextView = getNextView().findViewById(R.id.stv_daka);
        superTextView.setText(text);
        showNext();
    }

    public void startAnim() {
        SuperTextView superTextView = getCurrentView().findViewById(R.id.stv_daka);
        superTextView
                .startAnim();
    }
}
